package com.pengtu.entity.quality;

import java.util.Comparator;
import java.util.Date;
import java.util.Set;
import java.util.TreeSet;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

import org.hibernate.annotations.Where;

import com.pengtu.entity.IdEntity;
import com.pengtu.entity.app.Attachment;

@Entity
@Table(name = "T_Q_CHECK_RESULT")
public class CheckResult extends IdEntity {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private String projectId;			//工程
	private String cid;		//检查ID
	private String type;				//问题类型
	private String content;				//概要描述
	private String contentFile;			//附件
	private String preparer;				//提交人
	private Date prepareDate;			//发现时间
	private String dealContent;			//处理措施
	private Date dealDate;				//处理时间
	private String remark;				//备注

	private Set<Attachment> attachmentSet = new TreeSet<Attachment>(
			new Comparator<Attachment>() {
				@Override
				public int compare(Attachment attFirst, Attachment attSecond) {
					// TODO Auto-generated method stub
					return attFirst.getCreateDate().compareTo(
							attSecond.getCreateDate());
				}
			}); // 附件
	
	
	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
	@JoinColumn(name = "TABLEID")
	@Where(clause="delFlag = 0")
	public Set<Attachment> getAttachmentSet() {
		return attachmentSet;
	}
	public void setAttachmentSet(Set<Attachment> attachmentSet) {
		this.attachmentSet = attachmentSet;
	}
	@Column(name="PID")
	public String getProjectId() {
		return projectId;
	}
	public void setProjectId(String projectId) {
		this.projectId = projectId;
	}
	
	/**
	 * cid
	 *
	 * @return  the cid
	 * @since   1.0.0
	 */
	@Column(name="CID")
	public String getCid() {
		return cid;
	}
	/**
	 * @param cid the cid to set
	 */
	public void setCid(String cid) {
		this.cid = cid;
	}
	
	@Column(name="TYPE")
	public String getType() {
		return type;
	}
	public void setType(String type) {
		this.type = type;
	}
	
	@Column(name="CONTENT")
	public String getContent() {
		return content;
	}
	public void setContent(String content) {
		this.content = content;
	}
	
	@Column(name="CONTENTFILE")
	public String getContentFile() {
		return contentFile;
	}
	public void setContentFile(String contentFile) {
		this.contentFile = contentFile;
	}
	
	@Temporal(TemporalType.DATE)
	@Column(name="PREPAREDATE")
	public Date getPrepareDate() {
		return prepareDate;
	}
	public void setPrepareDate(Date prepareDate) {
		this.prepareDate = prepareDate;
	}
	
	/**
	 * preparer
	 *
	 * @return  the preparer
	 * @since   1.0.0
	 */
	@Column(name="PREPARER")
	public String getPreparer() {
		return preparer;
	}
	/**
	 * @param preparer the preparer to set
	 */
	public void setPreparer(String preparer) {
		this.preparer = preparer;
	}
	@Column(name="DEALCONTENT")
	public String getDealContent() {
		return dealContent;
	}
	public void setDealContent(String dealContent) {
		this.dealContent = dealContent;
	}
	
	@Temporal(TemporalType.DATE)
	@Column(name="DEALDATE")
	public Date getDealDate() {
		return dealDate;
	}
	public void setDealDate(Date dealDate) {
		this.dealDate = dealDate;
	}
	
	@Column(name="REMARK")
	public String getRemark() {
		return remark;
	}
	public void setRemark(String remark) {
		this.remark = remark;
	}
	
	@Transient
	public Attachment getAttachment() {
		if (attachmentSet.iterator().hasNext())
			return attachmentSet.iterator().next();
		return new Attachment();
	}

	public void setAttachment(Attachment attachment) {
		attachmentSet.clear();
		attachmentSet.add(attachment);
	}
}
